﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StoreWeb.system.basis
{
    public partial class dictionarylist : System.Web.UI.Page
    {
        Maticsoft222.BLL.sqlexec sql = new Maticsoft222.BLL.sqlexec();
        Maticsoft.BLL.Dictionary bll = new Maticsoft.BLL.Dictionary();
        Maticsoft.BLL.DictionaryType typebll = new Maticsoft.BLL.DictionaryType();
        Maticsoft.BLL.DictionaryrReference dbll = new Maticsoft.BLL.DictionaryrReference();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //this.typelist.DataSource = typebll.GetAllList();
                //this.typelist.DataTextField = "typename";
                //this.typelist.DataValueField = "id";
                //this.typelist.DataBind();
                //this.typelist.Items.Insert(0, new ListItem("--请选择所属分类--", ""));
                this.parentlist.DataSource = sql.exsql("select parentcode,parentname from dbo.Dictionary where parentcode!='' and parentname!='' group by parentcode,parentname");
                this.parentlist.DataTextField = "name";
                this.parentlist.DataValueField = "code";
                this.parentlist.DataBind();
                this.parentlist.Items.Insert(0, new ListItem("--属性分类--", "0"));
                int totalOrders = bll.GetRecordCount("");
                AspNetPager1.RecordCount = totalOrders;

            }
        }
        void bindData(string where)
        {
            Repeater1.DataSource = bll.GetListByPage(where, "", AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex);
            Repeater1.DataBind();
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {

            bindData(hidwhere.Value);
        }
        //获取是否被使用
        //protected string isred(string id)
        //{
        //    if (dbll.GetModelList("dictionaryid=" + id).Count > 0)
        //        return "<span style='color:red'>是</span>";
        //    else
        //        return "否";
        //}
        //protected string gettypename(string typeid)
        //{
        //    return typebll.GetModel(Convert.ToInt32(typeid)).typename;
        //}
        protected string getparentname(string parentcode)
        {
            if (string.IsNullOrEmpty(parentcode))
                return "----";
            else
                return bll.GetModelList("code='" + parentcode + "'")[0].name;
        }

        protected void btnserach_Click(object sender, EventArgs e)
        {
            string where = "id<>0 ";
            //if (typelist.SelectedItem.Value!="")
            //{
            //    where += " and typeid = " + typelist.SelectedItem.Value;
            //}
            if (parentlist.SelectedItem.Value != "0")
            {
                where += " and parentcode = '" + parentlist.SelectedItem.Value + "'";
            }
            if (name.Value != null && !string.IsNullOrEmpty(name.Value))
            {
                where += " and name like '%" + name.Value + "%'";
            }
            hidwhere.Value = where;
            bindData(hidwhere.Value);
        }

        protected void parentlist_SelectedIndexChanged(object sender, EventArgs e)
        {
            string where = "id<>0 ";
            if (parentlist.SelectedItem.Value != "0")
            {
                where += " and parentcode = '" + parentlist.SelectedItem.Value + "'";
            }
            hidwhere.Value = where;
            bindData(hidwhere.Value);
        }
    }
}